﻿@{
    this.SetPageContextValue("area", "cloud");
    var aceSetting = this.GetAceSetting();
    var aceSettingJson = SimpleNewtonJsonHelper.Serialize(aceSetting);
    var skin = aceSetting.Skin;
    
    var superAccountHelper = CoreServiceProvider.LocateService<SuperAccountHelper>();
    bool checkIdentity = superAccountHelper.CheckIdentity(this.Request);
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Cloud - @ViewBag.Title</title>
    <link type="image/x-icon" href="/favicon.ico" rel="icon" />
    @Html.Partial("_AceStyles")
    <!-- styles related to this page -->
    @RenderSection("style", false)

    @Html.Partial("_AceScripts")

</head>

<body class="@skin">

    @Html.Partial("_AceNavBar")

    <div class="main-container" id="main-container">
        
        @Html.Partial("_AceSideBar")

        <div class="main-content">

            @Html.Partial("_AceBreadcrumbs")

            <div class="page-content">

                @Html.Partial("_AceSettingBox", checkIdentity)

                <!-- PAGE CONTENT BEGINS -->
                @RenderBody()
                <!-- PAGE CONTENT ENDS -->

            </div>
        </div>

        @Html.Partial("_AceFooter")

    </div>


    <script>

        (function () {
            'use strict';

            //初始化Ace UI
            var aceSetting = jQuery.parseJSON('@Html.Raw(aceSettingJson)');
            //console.log(aceSetting);

            $(document).ready(function () {

                ////First parameter determines whether should become fixed or not.
                ////Second paramtere determines whether to save the changes to cookies/localStorage for later retrieval
                ace.settings.navbar_fixed(aceSetting.FixedNavbar);
                ace.settings.sidebar_fixed(aceSetting.FixedSidebar);
                ace.settings.breadcrumbs_fixed(aceSetting.FixedBreadcrumbs);
                ace.settings.main_container_fixed(aceSetting.InsideContainer);
                //ace.settings.sidebar_collapsed(true, false);
                
                var skinClass = "no-skin";

                var changeSkin = function (skin_class) {
                    //skin cookie tip

                    var body = $(document.body);
                    body.removeClass('no-skin skin-1 skin-2 skin-3');

                    //if(skin_class != 'skin-0') {
                    body.addClass(skin_class);
                    ace.data.set('skin', skin_class);
                    //save the selected skin to cookies
                    //which can later be used by your server side app to set the skin
                    //for example: <body class="<?php echo $_COOKIE['ace_skin']; ?>"
                    //} else ace.data.remove('skin');

                    var skin3_colors = ['red', 'blue', 'green', ''];


                    //undo skin-1
                    $('.ace-nav > li.grey').removeClass('dark');

                    //undo skin-2
                    $('.ace-nav > li').removeClass('no-border margin-1');
                    $('.ace-nav > li:not(:last-child)').removeClass('light-pink').find('> a > ' + ace.vars['.icon']).removeClass('pink').end().eq(0).find('.badge').removeClass('badge-warning');
                    $('.sidebar-shortcuts .btn')
                        .removeClass('btn-pink btn-white')
                        .find(ace.vars['.icon']).removeClass('white');

                    //undo skin-3
                    $('.ace-nav > li.grey').removeClass('red').find('.badge').removeClass('badge-yellow');
                    $('.sidebar-shortcuts .btn').removeClass('btn-primary btn-white')
                    var i = 0;
                    $('.sidebar-shortcuts .btn').each(function() {
                        $(this).find(ace.vars['.icon']).removeClass(skin3_colors[i++]);
                    })


                    var skin0_buttons = ['btn-success', 'btn-info', 'btn-warning', 'btn-danger'];
                    if (skin_class == 'no-skin') {
                        var i = 0;
                        $('.sidebar-shortcuts .btn').each(function() {
                            $(this).attr('class', 'btn ' + skin0_buttons[i++ % 4]);
                        })
                    } else if (skin_class == 'skin-1') {
                        $('.ace-nav > li.grey').addClass('dark');
                        var i = 0;
                        $('.sidebar-shortcuts')
                            .find('.btn').each(function() {
                                $(this).attr('class', 'btn ' + skin0_buttons[i++ % 4]);
                            })
                    } else if (skin_class == 'skin-2') {
                        $('.ace-nav > li').addClass('no-border margin-1');
                        $('.ace-nav > li:not(:last-child)').addClass('light-pink').find('> a > ' + ace.vars['.icon']).addClass('pink').end().eq(0).find('.badge').addClass('badge-warning');

                        $('.sidebar-shortcuts .btn').attr('class', 'btn btn-white btn-pink')
                            .find(ace.vars['.icon']).addClass('white');
                    }
//skin-3
                    //change shortcut buttons classes, this should be hard-coded if you want to choose this skin
                    else if (skin_class == 'skin-3') {
                        body.addClass('no-skin'); //because skin-3 has many parts of no-skin as well

                        $('.ace-nav > li.grey').addClass('red').find('.badge').addClass('badge-yellow');

                        var i = 0;
                        $('.sidebar-shortcuts .btn').each(function() {
                            $(this).attr('class', 'btn btn-primary btn-white');
                            $(this).find(ace.vars['.icon']).addClass(skin3_colors[i++]);
                        })

                    }

                    //some sizing differences may be there in skins, so reset scrollbar size
                    if ('sidebar_scroll' in ace.helper) ace.helper.sidebar_scroll.reset();

                };

                //changeSkin(skinClass);

                //上面的事件不需要触发
                //改写了ace.extra.js，不显示settingBox的事件也不会被触发
                //如果修改Ace UI，保存到服务器上
                $(document).on('settings.ace', function (event, name, status) {

                    if (name == "sidebar_collapsed") {
                        //此项不保存
                        //用户自己的设置为准
                        return;
                    }

                    //console.log(name + " : " + status);
                    $.post("/Cloud/Ace/SetAceSetting", { name: name, status: status })
                        .done(function () {
                            console.log("服务器保存" + name + " : " + status);
                        });

                });

            });

        }());

    </script>
    @RenderSection("scripts", false)
</body>
</html>